package com.prs.crm.service.doc.impl;

import java.util.Collection;
import java.util.Date;

import com.prs.crm.context.ToolKits;
import com.prs.crm.dao.doc.IssuePayrollDao;
import com.prs.crm.domain.doc.IssuePayroll;
import com.prs.crm.domain.hr.Payroll;
import com.prs.crm.domain.hr.Person;
import com.prs.crm.service.doc.IssuePayrollService;
import com.prs.crm.service.hr.PayrollService;
import com.prs.crm.service.hr.PersonService;
import com.prs.crm.service.impl.BaseServiceImpl;

public class IssuePayrollServiceImpl extends BaseServiceImpl<IssuePayroll,IssuePayrollDao> implements IssuePayrollService{
	private PersonService personService;
	private PayrollService payrollService;
	
	@Override
	public void submitIssuePayroll(Date issueStartTime, Date issueEndTime,
			String issueDocIds, String receivePersons) {
		// TODO Auto-generated method stub
		Collection<Person> persons = this.getPersonService().findPersons(ToolKits.convertStringAryToIntAry(receivePersons.split(",")));
		Collection<Payroll> payrolls = this.getPayrollService().getPayrollByIds(ToolKits.convertStringAryToIntAry(issueDocIds, ","));
		for(Payroll payroll:payrolls) {
			for(Person person:persons) {
				IssuePayroll issue = new IssuePayroll();
				issue.setPayroll(payroll);
				issue.setReceivePerson(person);
				issue.setStartTime(issueStartTime);
				issue.setEndTime(issueEndTime);
				
				this.getDao().save(issue);
			}
		}
	}

	public PersonService getPersonService() {
		return personService;
	}

	public void setPersonService(PersonService personService) {
		this.personService = personService;
	}

	public void setPayrollService(PayrollService payrollService) {
		this.payrollService = payrollService;
	}

	public PayrollService getPayrollService() {
		return payrollService;
	}

	@Override
	public Collection<IssuePayroll> getValidIssuePayroll(Person person) {
		// TODO Auto-generated method stub
		return this.getDao().getValidIssuePayroll(person);
	}

}
